package com.dao;

import com.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class UserDao {

    //用户扣减余额
    public void subBalance(int total){
        String sql = "update t_user set balance=balance-? where id=?";
        Connection conn = null;
        try{
            conn = DBUtils.getConn();
            PreparedStatement stmt = conn.prepareStatement(sql);

            stmt.setInt(1,total);
            stmt.setInt(2,1);

            stmt.executeUpdate();

        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException(e);
        }

    }

}
